const fs = require('fs');
const request = require('superagent');
const path = require('path');
 


 function upload(){

    //父级目录id
    let parentId = "67f77537fff7005e217eb603";

    // 文件路径
    let fileName = '非营利组织免税资格认定.docx';
    const filePath = './事项数据/内蒙古自治区-简化/自治区财政厅/'+fileName; // 确保文件存在且路径正确
     
    // 使用superagent上传文件
    request.post('https://api.fastgpt.in/api/core/dataset/collection/create/localFile')
    .set({"Authorization":"Bearer fastgpt-glkXoYPQThuxXBI6CAdiczzx2UnpmnNOkQrqf5uxPmKgSdndHa4O","Content-Type":"multipart/form-data; charset=utf-8"})
      .attach('file', filePath,{ filename: encodeURIComponent(fileName) }) // encode转码避免中文乱码
      .field('data',`{"datasetId":"67f774f06a4436ee307c3e7e","parentId":${parentId},"trainingType":"chunk","chunkSplitter":"aaabbbb","chunkSettingMode":"custom","chunkSplitMode":"char"}`)
      .then(response => {
        console.log('上传成功:', response.body);
      })
      .catch(error => {
        console.error('上传失败:', error);
      });
 }







upload();